package com.yanqu.road.server.cmd.activity.civil;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.civil.enums.ActivityCivilConditionTypeEnum;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ActivityProto;
import com.yanqu.road.pb.cookboyactivity.CookBoyActivityProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.CrossRelationActivityMgr;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanMgr;
import com.yanqu.road.server.manager.cookboy.CrossCookBoyMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CROSS_ACTIVITY_RECEIVE_CIVIL_REWARD, desc = "领取通用全民奖励")
public class CrossActivityReceiveCivilRewardCmd extends CrossCommand {
    private int activityId;
    private int conditionType;
    private long userId;
    private long activityUserId;
    private String params;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ActivityProto.ActivityReceiveCivilRewardToCrossReqMsg reqMsg = ActivityProto.ActivityReceiveCivilRewardToCrossReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionType = reqMsg.getConditionType();
        activityUserId = reqMsg.getActivityUserId();
        params = reqMsg.getParams();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        //判断conditionType是否符合
        if (!ActivityCivilConditionTypeEnum.checkConditionType(conditionType)) {
            ActivityProto.ActivityReceiveCivilRewardRespMsg.Builder respMsg = ActivityProto.ActivityReceiveCivilRewardRespMsg.newBuilder();
            respMsg.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_ACTIVITY_RECEIVE_CIVIL_REWARD, respMsg);
            MessageHelper.sendPacket(serverId, userId, pbMsg);
            return;
        }

        long value = 0;
        //这里扩展活动conditionType
        if(conditionType == eGamePlayerEventType.ZhenHuanThirdProcessBanquetTimesCivil.getValue()) {
            //甄嬛3全民花车开宴次数
            value = CrossZhenHuanMgr.getUserBanquetCount(activityId, activityUserId);
        }
        ActivityProto.CrossActivityReceiveCivilRewardToReqMsg.Builder respMsg = ActivityProto.CrossActivityReceiveCivilRewardToReqMsg.newBuilder();
        respMsg.setActivityId(activityId);
        respMsg.setConditionType(conditionType);
        respMsg.setActivityUserId(activityUserId);
        respMsg.setParams(params);
        respMsg.setValue(value);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_ACTIVITY_RECEIVE_CIVIL_REWARD, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);

    }

    @Override
    public void sendData() {

    }
}
